<template>
  <div id="main" class="w-100 h-100" style="background-color:#fff"></div>
</template>

<script>
import WordCloud from "@/word-cloud.js";

export default {
    name: "HomeType",
    data() {
        return {
            //chart是调用Worcloud对象init函数，返回的图标对象
            chart: null,
            //tags是后端返回的词云图的数据
            tags: [],
        };
    },
    async mounted() {
        await this.getTagGroup();
        this.initCharts();
    },
    methods: {
        //从后端获取图表所需数据
        async getTagGroup() {
            await this.$axios.get("/api/home/tag/group").then((response) => {
                let data = response.data;
                if (data.code == 200) {
                    this.tags = data.data;
                }
            });
        },
        //初始化图表
        initCharts() {
            let w = new WordCloud();
            this.chart = w.init("main", this.tag,this.tolist);
        },
        //点击图表的文字触发的函数
        tolist(dataOption) {
            let data = dataOption.data;
            console.log(data.name);
        },
        },
};
</script>

<style>

</style>